import java.util.Arrays;

public class Solution238 {
    public int[] productExceptSelf(int[] nums) {
        int[] ans=new int[nums.length];
        Arrays.fill(ans,1);
        int l=1;
        for (int i=0;i<nums.length;i++){
            ans[i]*=l;
            l=l*nums[i];
        }
        int r=1;
        for (int i=nums.length-1;i>=0;i--){
            ans[i]*=r;
            r=r*nums[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution238().productExceptSelf(new int[]{1, 2, 3, 4})));
    }
}
